<!DOCTYPE html>
<html>

<head>
    <head/>
    <title>医生详情</title>
    <titleType style="display: none;">sc</titleType>
    <%- include('./_global/appendJs') %>

</head>
<style>
    .swiper-wrapper .swiper-slide {
        float: left;
        width: 14% !important;
    }

    .doctor-box .blue-icon {
        position: absolute;
        width: 1.54762rem;
        height: 1.42857rem;
        background: url("/static/images/blue-mes.png") no-repeat;
        background-size: 100% 100%;
        right: 1.33333rem;
        top: 3.2381rem;
    }
    .doctor-detail .doctor-box {
        height: 5.5rem;
    }
    .doctor-detail .doctor-box .text-box {
        margin-left: .5rem;
    }
    .doctor-detail .check-date-box .swiper-slide .time-wrap.active .is-source {
        color: #fff;
    }
</style>

<body>
    <section class="page-wrap doctor-detail">
        <!-- <header class="header-box grey fixed">
            <div class="header-content">
                <div class="left-tool">
                    <a class="back" href="javascript:void(0);">
                        <i class="iconfont icon-back"></i>
                    </a>
                </div>
                <div class="right-tool">
                    <a href="javascript:void(0);"><i class="sc-icon"></i></a>
                </div>
                <div class="title">医生详情</div>
            </div>
        </header> -->
        <div class="doctor-box">
            <img class="docImgUrl" src="">
            <div class="text-box">
                <p class="doc-info">
                    <span class="blue-text" name="docName"></span>
                    <span class="black-text" name="docTitle"></span>

                </p>
                <!--<p><span class="black-text" name="visitCost">￥8.00</span></p>-->
                <span class="black-text" name="hosName">万达医院</span>
                <span class="black-text" name="depName">呼吸科</span>

            </div>
            <!--   <div class="collect-box"><span name="orderNum">579人</span>预约过</div> -->
            <!-- <a class="blue-icon" id="zxBtn" style="display: none"></a> -->
        </div>
        <div id="sliderTimer" class="check-date-box swiper-container swiper-container-horizontal swiper-container-free-mode" style="margin-top: 1px;">
            <div class="swiper-wrapper" style="transform: translate3d(0px, 0px, 0px);height:140px;" id="timeSchedule">
            </div>
        </div>

        <div class="list-box">
            <ul id="hylb">
            </ul>
        </div>

        <div class="jj-box">
            
        </div>
    </section>
</body>
<script type="text/html" id="dateDiv">
    <div class="swiper-slide swiper-slide-active">
        <div class="time-wrap">
            <p class="text-week">周日</p>
            <p class="text-time">2016-09-29</p>
            <p class="is-source"></p>
        </div>
    </div>
</script>
<script type="text/html" id="hyLi">
    <li>
        <div class="block-1">
            <span class="list-date">2015-09-10</span>
            <span class="list-sw">8:00-9:00</span>
        </div>
        <div class="block-2">
            <span class="list-sy">剩余</span>
            <span class="list-num">5</span>
            <span class="list-mz">普通门诊:</span>
            <span class="list-num2">36</span>
            <span class="list-dw">元</span>
        </div>
        <a class="blue-yy active" href="javascript:void(0)">挂号</a>
    </li>
</script>
<script type="text/html" id="noInfo">
    <li class="noInfo">
        <div class="block-1" style="width:100%;text-align:center; font-weight:bold;color:#000;line-height:71px;padding:0;">
            <span>暂无号源信息</span>
        </div>
    </li>
</script>
<script type="text/html" id="docIntroduce">
    <p class="jj-title">擅长：</p>
    <span class="jj-content" name="docSpecialty"></span>
    <p class="jj-title">医生简介：</p>
    <span class="jj-content" name="docInfo">

    </span>
    <a class="zz-btn">展开</a>
</script>
<script type="text/html" id="OutpatIntroduce">
    
    <p class="jj-title">科室简介：</p>
    <span class="jj-content" name="deptDesc">

    </span>
    <a class="zz-btn">展开</a>
</script>
<script src="/static/lib/forweb.js"></script>
<script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
<script src="/static/js/<%=type%>/pageUrl.js"></script>
<script src="/static/js/<%=type%>/yygh.js"></script>

<script type="text/javascript">
    var page_ysDetail = (function ($, page_ysDetail) {
        var sfsc = "";
        var selectTime = $.QuickUrlUtils.getRequest('selectTime');
        var requestRoot = "/jkcsHt/yygh";

        /**加载视图*/
        function initView() {
            /*按专家查询*/
            if (StringUtils.isEmpty(selectTime)) {
                page_ysDetail.setYyghDate();
                var swiper = new Swiper('#sliderTimer', {
                    pagination: '.swiper-pagination',
                    slidesPerView: 5.1,
                    paginationClickable: true,
                    spaceBetween: 0,
                    freeMode: true
                });
                $("#sliderTimer").on('click', '.time-wrap', function () {
                    $("#sliderTimer").find('.time-wrap').removeClass('active');
                    $(this).addClass('active');
                    /**显示号源信息*/
                    //var yyrq = $(this).find(".text-time").html();
                    var yyrq = $(this).find(".text-time").data().yyrq;
                    if (!StringUtils.isEmpty(yyrq)) {
                        var len = $("#hylb").find("li[yyrq='" + yyrq + "']").length;
                        $("#hylb").find("li").hide();
                        if (len == 0) {
                            
                            $("#hylb").find(".noInfo").show();
                        } else {
                            $("#hylb").find("li[yyrq='" + yyrq + "']").show();
                        }
                    }
                });
                $(".swiper-wrapper").show();
            }
            /*按日期预约*/
            else {
                $(".swiper-wrapper").hide();
            }

            var slideSwitch = true;
            $('.jj-box').on("click",".zz-btn" ,function () {
                if (slideSwitch == true) {
                    $(this).text("收起");
                    $(".jj-content").css('webkit-line-clamp', '9999');
                    slideSwitch = false;
                } else {
                    $(this).text("展开");
                    $(".jj-content").css('webkit-line-clamp', '3');
                    slideSwitch = true;
                }
            });

            /**号源*/
            $("#hylb").on("click", ".blue-yy", function () {
                var info = $(this).data("info");
                if (info["remainNum"] == "0") {

                    $.QuickAlert.alertNormal("该预约已满，请选择其他预约！", {
                        callback: function (indexAlert) {
                            layer.close(indexAlert);
                        }
                    });

                } else {
                    StoreCache.setCache("YYGH_HYINFO", info);
                    if ("<%=type%>" == "gzd") {
                        $.pageSwitch.goToUrl("myOrder", "orderInfo");
                    } else {
                        $.QuickRemote.AjaxJson({
                            funcName: "/api/ysd/hzcz/querySclb",
                            callback: function (result) {
                                if (result && result.length < 1) {
                                    $.QuickAlert.alertFail({
                                        content: "没有可预约的患者"
                                    });
                                } else {
                                    $.pageSwitch.goToUrl("myOrder", "orderInfo");
                                }
                            }
                        });
                    }

                }



            });

            /**收藏按钮*/
            $(".sc-icon").on("click", page_ysDetail.scFunction);
        }

        /**加载数据*/
        function initData() {
            var ysInfo = StoreCache.getCache("YYGH_YSINFO");
            if (ysInfo) {
                $('body').data('ysInfo', ysInfo);
                /**设置收藏使用参数*/
                $(".sc-icon").data("info", {
                    hosCode: ysInfo["hosCode"],
                    depCode: ysInfo["depCode"],
                    docCode: ysInfo["docCode"]
                });
                page_ysDetail.initDoctorInfo(ysInfo);
            } else {
                $.QuickAlert.alertFail({
                    content: "医生详情查询失败！"
                });
            }
        }

        /*加载医生信息*/
        function initDoctorInfo(info) {
            /**设置医生信息*/
            var ysInfo = StoreCache.getCache("YYGH_YSINFO");
            var hosInfo = StoreCache.getCache("YYGH_HOSINFO");
            info.hosName = hosInfo.hosName;
            $(".doctor-box").find("span").each(function () {
                if ($(this).attr("name") == "docTitle") {
                    if (!info[$(this).attr("name")]) {
                        $(this).text("副主任医师");
                    } else {
                        $(this).text(info[$(this).attr("name")]);
                    }
                } else {
                    $(this).text(info[$(this).attr("name")]);
                }
                
            });
            if (info["docImgUrl"]) {
                $(".docImgUrl").attr("src", info["docImgUrl"]);
            }
            if (ysInfo.orderType == "2") {
                $(".doc-info").hide();
                $(".docImgUrl").attr("src", "/static/images/icon_ptmz.png");
                $(".title").text("门诊详情");
                $(document).attr("title", "门诊详情");
                $(".doctor-box").find(".black-text[name='depName']").text(ysInfo["deptName"]);

            } else if (ysInfo.orderType == "1") {

                $(".docImgUrl").attr("src", "/static/images/doctor_image.jpg");
            }

            /**加载简介信息*/
            if (ysInfo.orderType == "2") {
                $(".jj-box").html(template("OutpatIntroduce",{}));
            } else {
                $(".jj-box").html(template("docIntroduce",{}));
            }
            $(".jj-box").find("span").each(function () {
                $(this).text(info[$(this).attr("name")]);
            });
            page_ysDetail.getNumSource(info);
        }

        function getNumSource(ysInfo) {
            /**获取参数*/
            var currDate = new Date();
            var params = {};
            params["hosCode"] = ysInfo["hosCode"];
            params["depCode"] = ysInfo["depCode"];
            params["docCode"] = ysInfo.docCode;
            params["startTime"] = currDate.Format("yyyy-MM-dd");
            params["endTime"] = (currDate.DateAdd("d", 14)).Format("yyyy-MM-dd");
            params["orderType"] = ysInfo["orderType"];
            params["oneDepCode"] = ysInfo["oneDepCode"];
            if (ysInfo["orderType"] == "2") {
                params["resourceCode"] = ysInfo["resourceCode"];
            } else {
                params["resourceCode"] = ysInfo["docCode"];
            }
            params["patient_type"] = "1";
            /**加载号源信息*/
            // $.QuickRemote.AjaxJson({
            //     funcName: $.getMyorderUrl.getpageUrl("getNumSource"),
            //     params: params,
            //     callback: function (result) {
            //         $("#hylb").empty();
            //         var lis = page_ysDetail.createHlxx(result, params);
            //         $("#hylb").append(lis);
            //         /*按专家查询*/
            //         if (StringUtils.isEmpty(selectTime)) {
            //             $("#hylb").find("li").hide();
            //             $("#hylb").prepend($($("#noInfo").html()));
            //             /*找到第一个有号源的日期*/
            //             var li = $("#hylb").find("li[yyrq]:eq(0)");
            //             if (li.length != 0) {
            //                 var yyrq = li.attr("yyrq");
            //                 var rq = yyrq.substring(5, yyrq.length);
            //                 $("#timeSchedule").find(".time-wrap").each(function () {
            //                     var text_time = $(this).find(".text-time").text();
            //                     if (text_time == rq) {
            //                         $(this).trigger("click");
            //                         return false; //跳出each循环
            //                     }
            //                 });
            //             } else {
            //                 $("#timeSchedule").find(".time-wrap:eq(0)").trigger("click");
            //             }
            //         }
            //     }
            // });
            $.ajax({
                type: "POST", // 使用get方法访问后台
                dataType: "json", // 返回json格式的数据
                "headers": {
                    "Content-Type": "application/json",
                    "Cache-Control": "no-cache",
                },
                url: "/api/yyghAdapter/getNumSource", // 要访问的后台地址
                data: JSON.stringify(params), // 要发送的数据
                success: function (data) {
                    if (data.code == "SUCCESS") {
                        if (data.data && data.data.length >
                            0) {
                            $("#hylb").empty();
                            var lis = page_ysDetail.createHlxx(data.data, params);
                            $("#hylb").append(lis);
                            
                           
                            $("#timeSchedule").find(".time-wrap").each(function () {
                                // var li = $("#hylb").find("li[yyrq]:eq(0)");
                                var text_time = $(this).find(".text-time").text();
                                var arrTime = [];
                                for (var i = 0; i < data.data.length; i++) {
                                    var rq = data.data[i].scheduleDate.substring(5, data.data[i].scheduleDate.length);
                                    arrTime.push(rq);
                                    

                                }
                                // console.log(arrTime);
                                // debugger;

                                if (arrTime.indexOf(text_time) > -1) {
                                    $(this).find(".is-source").text("有号");
                                } else {
                                    $(this).find(".is-source").text("无号");
                                }

                            });

                        
                            /*按专家查询*/
                            if (StringUtils.isEmpty(selectTime)) {
                                $("#hylb").find("li").hide();
                                $("#hylb").prepend($($("#noInfo").html()));
                                /*找到第一个有号源的日期*/
                                var li = $("#hylb").find("li[yyrq]:eq(0)");
                                if (li.length != 0) {
                                    var yyrq = li.attr("yyrq");
                                    var rq = yyrq.substring(5, yyrq.length);
                                    $("#timeSchedule").find(".time-wrap").each(function () {
                                        var text_time = $(this).find(".text-time").text();
                                        if (text_time == rq) {
                                            $(this).trigger("click");
                                            return false; //跳出each循环
                                        }
                                    });
                                } else {
                                    $("#timeSchedule").find(".time-wrap:eq(0)").trigger("click");
                                }
                            }
                        }
                    } else {
                        
                        $.QuickAlert.alertFail({
                            content: data.message
                        });
                        $("#hylb").prepend($($("#noInfo").html()));
                        $("#timeSchedule ").find('.is-source').html("无号");
                    }
                }
            });

        }

        /*创建号源信息*/
        function createHlxx(ary, params) {
            var lis = [];
            $.each(ary, function (index, item) {
                var numSources = item['numSources'];
                $.each(numSources, function (index, item1) {
                    var hyLi = $($("#hyLi").html());
                    $(hyLi).attr("yyrq", item1["scheduleDate"]);
                    $(hyLi).find(".list-date").text(item1["scheduleDate"]);
                    /*if(item1["timeRange"]=="0"){
                        $(hyLi).find(".list-sw").text("全天");
                    }else  if(item1["timeRange"]=="1"){
                        $(hyLi).find(".list-sw").text("上午");
                    }else  if(item1["timeRange"]=="2"){
                        $(hyLi).find(".list-sw").text("中午");
                    }else  if(item1["timeRange"]=="3"){
                        $(hyLi).find(".list-sw").text("下午");
                    }else  if(item1["timeRange"]=="4"){
                        $(hyLi).find(".list-sw").text("晚上");
                    }*/
                    //展示方式改为时间段
                    $(hyLi).find(".list-sw").text(item1["startTime"] + "-" + item1["endTime"]);

                    $(hyLi).find(".list-num").text(item1["remainNum"]);
                    $(hyLi).find(".list-mz").text(page_ysDetail.getRegType(item1["regType"]));
                    var value = item1["visitCost"];
                    if (StringUtils.isEmpty(value)) {
                        value = "0";
                    }
                    $(hyLi).find(".list-num2").text(value);
                    /**判断是否有号*/
                    var status = false;
                    if (parseInt(item1["remainNum"]) == 0) {
                        status = true;
                    }
                    if (status) {
                        $(hyLi).find("a").removeClass("active").html("约满");
                        $(hyLi).find("a").unbind("click");
                    }
                    //因为后台数据没有返回这两个字段数据  所以设置depCode，oneDepCode
                    item1["depCode"] = params["depCode"];
                    item1["oneDepCode"] = params["oneDepCode"];

                    $(hyLi).find("a").data("info", item1);
                    lis.push(hyLi);
                });
            });
            return lis;
        }

        /**设置预约挂号日期 当前日期往后退7天*/

        var showTime = false;

        function setYyghDate() {
            var formatTime = "MM-dd";
            var currDate = new Date();
            var year1 = -1,
                year2 = -1;
            for (var i = 1; i <= 14; i++) {
                var date = currDate.DateAdd("d", i);
                year1 = date.getFullYear();
                if (year1 != year2 && year2 != -1 && !showTime) {
                    showTime = true;
                    formatTime = "yyyy-MM-dd";
                    $("#timeSchedule").empty();
                    page_ysDetail.setYyghDate();
                    break;
                }
                year2 = year1;
                var dateDiv = $($("#dateDiv").html());
                dateDiv.find(".text-week").html(date.getWeekDay());
                dateDiv.find(".text-time").html(date.Format(formatTime));
                dateDiv.find(".text-time").data("yyrq", date.Format("yyyy-MM-dd"));

               

                dateDiv.appendTo($("#timeSchedule"));

                
                if (i == 1) {
                    $(dateDiv).find(".time-wrap").addClass('active');
                    var yyrq = $(dateDiv).find(".text-time").data().yyrq;
                    if (!StringUtils.isEmpty(yyrq)) {
                        var len = $("#hylb").find("li[yyrq='" + yyrq + "']").length;
                        $("#hylb").find("li").hide();
                        if (len == 0) {
                            $("#hylb").find(".noInfo").show();
                        } else {
                            $("#hylb").find("li[yyrq='" + yyrq + "']").show();
                        }
                    }
                }
            }
        }

        /**获取门诊类型*/
        function getRegType(regType) {
            var value = "";
            if (regType == "100") {
                value = "普通门诊";
            } else if (regType == "101") {
                value = "专科门诊";
            } else if (regType == "102") {
                value = "专家门诊";
            } else if (regType == "103") {
                value = "特需门诊";
            } else if (regType == "104") {
                value = "专病门诊";
            } else if (regType == "999") {
                value = "其它门诊";
            }
            return value;
        }

        /**收藏方法*/
        function scFunction() {
            var params = $(".sc-icon").data("info");
            params["sfsc"] = sfsc;
            params.userId = userInfo.USERID;
            $.QuickRemote.AjaxJson({
                funcName: "/api" + requestRoot + "/saveYsscInfo",
                callback: function (result) {
                    if (result["code"] == "0") {
                        if (sfsc == 0) {
                            sfsc = 1;
                        } else {
                            sfsc = 0;
                        }
                        page_ysDetail.loadScImg();
                    } else {
                        var content = "";
                        if (sfsc == 0) {
                            content = "收藏医生失败！";
                        } else {
                            content = "取消收藏医生失败！";
                        }
                        $.QuickAlert.alertFail({
                            content: content
                        });
                    }
                },
                params: params
            });
        }

        /**加载收藏图片*/
        function loadScImg() {
            $.JkcsUtils.loadScImg(sfsc);
        }

        var cfg_def = {
            initView: initView,
            initData: initData,
            initDoctorInfo: initDoctorInfo,
            getNumSource: getNumSource,
            createHlxx: createHlxx,
            setYyghDate: setYyghDate,
            getRegType: getRegType,
            scFunction: scFunction,
            loadScImg: loadScImg,
        }

        page_ysDetail.init = function (cfg) {
            $.extend(page_ysDetail, cfg_def, cfg);
            page_ysDetail.initView();
            page_ysDetail.initData();

        }

        return page_ysDetail;
    })(jQuery, {});
</script>

</html>